package com.example.system.controller.exam;

import com.example.common.core.Controller.BaseController;
import com.example.common.core.domin.R;
import com.example.common.core.domin.TableDataInfo;
import com.example.system.domin.exam.dto.ExamAddDTO;
import com.example.system.domin.exam.dto.ExamEditDTO;
import com.example.system.domin.exam.dto.ExamQueryDTO;
import com.example.system.domin.exam.dto.ExamQuestAddDTO;
import com.example.system.domin.exam.vo.ExamDetailVO;
import com.example.system.service.exam.IExamService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
@Tag(name = "竞赛管理接口")
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;

    //接口地址: /system/exam/list
    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        return getTableDataInfo(examService.list(examQueryDTO));
    }

    //接口地址: /system/exam/add
    @PostMapping("/add")
    public R<String> add(@RequestBody ExamAddDTO examAddDTO) {
        return R.ok(examService.add(examAddDTO));
    }

    //接口地址: /system/exam/question/add
    @PostMapping("/question/add")
    public R<Void> questionAdd(@RequestBody ExamQuestAddDTO examQuestAddDTO) {
        return toR(examService.questionAdd(examQuestAddDTO));
    }

    //接口地址: /system/exam/question/delete
    @DeleteMapping("/question/delete")
    public R<Void> questionDelete(Long examId, Long questionId) {
        return toR(examService.questionDelet(examId,questionId));
    }

    //接口地址: /system/exam/detail
    @GetMapping("/detail")
    public R<ExamDetailVO> detail(long examId) {
        return R.ok(examService.detail(examId));
    }

    //编辑竞赛基本信息
    //接口地址: /system/exam/edit
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody ExamEditDTO examEditDTO) {
        return toR(examService.edit(examEditDTO));
    }

    //删除竞赛
    //接口地址: /system/exam/delete
    @DeleteMapping("/delete")
    public R<Void> delete(Long examId) {
        return toR(examService.delete(examId));
    }

    //发布竞赛
    //接口地址: /system/exam/publish
    @PutMapping("/publish")
    public R<Void> publish(Long examId) {
        return toR(examService.publish(examId));
    }

    //撤销竞赛发布
    //接口地址: /system/exam/cancelPublish
    @PutMapping("/cancelPublish")
    public R<Void> cancelPublish(Long examId) {
        return toR(examService.cancelPublish(examId));
    }


}
